//
//  HomeViewController.swift
//  daily_count
//
//  Created by 段帅 on 2018/4/2.
//  Copyright © 2018年 Sooc. All rights reserved.
//

import UIKit

class HomeViewController: UIViewController,UITextViewDelegate {

    @IBOutlet weak var cost_textFiled: UITextField!
    
    @IBOutlet weak var type_seg: UISegmentedControl!
    
    @IBOutlet weak var comment_textView: UITextView!
    
    @IBOutlet weak var laert_label: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    // MARK: - 进入账单大数据
//    @IBAction func EnterCountTable(_ sender: Any) {
//        DSToolManager.alertFaild(message: "敬请期待");
//    }
    
    @IBAction func postData(_ sender: Any) {
        
        if !self.cost_textFiled.hasText {
            DSToolManager.alertFaild(message: "请输入金额")
            return;
        }
        
        var para = [String:AnyObject]();
        para["cost"] = self.cost_textFiled.text as AnyObject;
        para["comment"] = self.comment_textView.text as AnyObject;
        para["type"] = self.type_seg.selectedSegmentIndex as AnyObject;
        DSToolManager.postWithToken(URLString: severseUrl+api_record, parameters: para) { (data, isSucess) in
            if isSucess {
                DSToolManager.alertSucess(message: "记录成功");
                self.cost_textFiled.text = nil;
                self.comment_textView.text = nil;
                self.view.endEditing(true);
            }else{
                DSToolManager.alertFaild(message: data!["statusCode"] as! String);
//                let dic = data!["data"] as! [String:Any];
//                print(dic["mes"] ?? "");
            }
        }
        
    }
    func textViewDidBeginEditing(_ textView: UITextView) {
        
        if comment_textView.hasText {
            self.laert_label.isHidden = false; 
        }else{
           self.laert_label.isHidden = true; 
        }
    }
    
    func textViewDidEndEditing(_ textView: UITextView) {
        if comment_textView.hasText {
            self.laert_label.isHidden = true;
        }else{
           self.laert_label.isHidden = false; 
        }
        

    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.endEditing(true);
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
